package com.example.shixun.controller;

import com.example.shixun.pojo.CharMsg;
import com.example.shixun.pojo.Result;
import com.example.shixun.service.CharMsgService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/char")
public class CharController {
    @Resource
    CharMsgService charMsgService;
    @ApiOperation("添加聊天记录")
    @PostMapping("/save")
    public Result saveCharMsg(@RequestBody CharMsg charMsg){
        Integer n=charMsgService.saveCharMsg(charMsg);
        if(n>0) return Result.success(n);
        return Result.fail("添加失败");
    }
    @ApiOperation("查找聊天记录")
    @PostMapping("/find")
    public Result findCharMsg(Integer id){
        CharMsg n=charMsgService.selectCharMsgById(id);
        if(n!=null) return Result.success(n);
        return Result.fail("查找失败");
    }
    @ApiOperation("聊天记录列表")
    @PostMapping("/findAll")
    public Result findCharMsgAll(){
        List<CharMsg> charMsgs=charMsgService.selectCharMsgAll();
        if(charMsgs!=null) return Result.success(charMsgs);
        return Result.fail("查找失败");
    }

}
